/**
 * 
 */
package co.gov.medellin.sdep.sisdep.gestion.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.gestion.exception.EstAreaSocioeconoException;
import co.gov.medellin.sdep.sisdep.gestion.exception.EstAreaSocioeconoRuntimeException;
import co.gov.medellin.sdep.sisdep.gestion.exception.descriptor.EstAreaSocioeconoMessageDescriptor;
import co.gov.medellin.sdep.sisdep.model.EstAreaSocioecono;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IEstAreaSocioeconoDAOT;

/**
 * @author Usuario
 *
 */
public class EstAreaSocioeconoServiceImpl extends BaseService implements IEstAreaSocioeconoService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private IEstAreaSocioeconoDAOT estareasocioeconoDAO;

	/**
	 * 
	 */
	public EstAreaSocioeconoServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(EstAreaSocioecono estareasocioecono) throws EstAreaSocioeconoException {
		try{
			estareasocioecono.setUsuarioCrea(getPrincipalUser());
			estareasocioecono.setFechaCrea(new Date());
			getEstAreaSocioeconoDAO().insert(estareasocioecono);
		}catch (Exception e) {
			Object [] infoError = {
				estareasocioecono.getId()
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new EstAreaSocioeconoException(new EstAreaSocioeconoMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new EstAreaSocioeconoException(new EstAreaSocioeconoMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(EstAreaSocioecono estareasocioecono) throws EstAreaSocioeconoException {
		try{
			estareasocioecono.setUsuarioModifica(getPrincipalUser());
			estareasocioecono.setFechaModifica(new Date());
			getEstAreaSocioeconoDAO().update(estareasocioecono);
		}catch (Exception e) {
			Object [] infoError = {
				estareasocioecono.getId()
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new EstAreaSocioeconoRuntimeException(new EstAreaSocioeconoMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new EstAreaSocioeconoRuntimeException(new EstAreaSocioeconoMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(EstAreaSocioecono estareasocioecono) throws EstAreaSocioeconoException {
		try {
			estareasocioecono.setUsuarioModifica(getPrincipalUser());
			estareasocioecono.setFechaModifica(new Date());
			getEstAreaSocioeconoDAO().delete(estareasocioecono);
		}catch (Exception e) {
			Object [] infoError = {
				estareasocioecono.getId()
			};
			throw new EstAreaSocioeconoRuntimeException(new EstAreaSocioeconoMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, EstAreaSocioecono estareasocioecono) throws EstAreaSocioeconoException {
		try{
			//return getEstAreaSocioeconoDAO().getAllEstAreaSocioeconoPaginated(start, max, criteria);
			return getEstAreaSocioeconoDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new EstAreaSocioeconoRuntimeException(new EstAreaSocioeconoMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final EstAreaSocioecono get(long id) throws EstAreaSocioeconoException {
		try{
			return getEstAreaSocioeconoDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new EstAreaSocioeconoRuntimeException(new EstAreaSocioeconoMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final EstAreaSocioecono getByIdSolicitud(long idSolicitud) throws EstAreaSocioeconoException {
		try{
			return getEstAreaSocioeconoDAO().findByIdSolicitudKey(idSolicitud);
		}catch (Exception e) {
			Object [] infoError = {new Long(idSolicitud)};
			throw new EstAreaSocioeconoRuntimeException(new EstAreaSocioeconoMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public IEstAreaSocioeconoDAOT getEstAreaSocioeconoDAO() {
		return estareasocioeconoDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setEstAreaSocioeconoDAO(IEstAreaSocioeconoDAOT estareasocioeconoDAO) {
		this.estareasocioeconoDAO = estareasocioeconoDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
